home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-09-17 | 15.0 KB | 565 lines | [TEXT/MPS ] |
- /*
- * This file has been changed from the original MacApp 3.1.1
- * to support the metrowerks CodeWarrior compilers C/C++ 1.1.1.
- * These changes are known *not* to work with earlier versions
- * of CodeWarrior. Every attempt though has been made to to keep
- * this file compatible with other development environments.
- *
- * Mark Anderson
- * metrowerks
- * 9/16/94
- *
- */
-
- // UMacAppUtilities.h
- // Copyright © 1984-1994 by Apple Computer Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #ifndef __UMACAPPUTILITIES__
- #define __UMACAPPUTILITIES__
-
- #ifndef __PASCALSTRING__
- #include <PascalString.h>
- #endif
-
- #ifndef __TOOLBOX__
- #include "Toolbox.h"
- #endif
-
- #ifndef __UGEOMETRY__
- #include <UGeometry.h>
- #endif
-
- #ifndef __TEXTEDIT__
- #include <TextEdit.h>
- #endif
-
- #ifndef __UITERATOR__
- #include <UIterator.h>
- #endif
-
- #ifndef __EDITIONS__
- #include <Editions.h>
- #endif
-
- #ifndef __NOTIFICATION__
- #include <Notification.h>
- #endif
-
- #ifndef __APPLEEVENTS__
- #include <AppleEvents.h>
- #endif
-
- #ifndef __MACAPPTYPES__
- #include <MacAppTypes.h>
- #endif
-
- //----------------------------------------------------------------------------------------
- // Global constants declarations. Build options.
- //----------------------------------------------------------------------------------------
-
- extern const char* kCopyright;
-
- // constants passed in as flags to MATextBox()
- enum { kDontPreferOutline, kPreferOutline };
-
- //----------------------------------------------------------------------------------------
- // Some useful struct(s)
- //----------------------------------------------------------------------------------------
-
- struct MATextStyle {
- Style tsFace; // character Style
- char filler; // tsFace is unpacked byte
- short tsSize; // size in CPoint
- CRGBColor tsColor; // absolute (RGB) color
- CStr255 tsFont; // font (family) number
- };
-
- typedef MATextStyle *MATextStylePtr, **MATextStyleHandle;
-
-
- //----------------------------------------------------------------------------------------
- // Global variable declarations.
- //----------------------------------------------------------------------------------------
-
- extern short gApplicationRefNum;
-
- extern Configuration gConfiguration;
-
- extern CStr255 gBoolString[2];
-
- extern Boolean gToolBoxInitialized;
-
- extern Boolean gUDialogInitialized;
-
- extern Boolean gUGridViewInitialized;
-
- extern Boolean gUPrintingInitialized;
-
- extern Boolean gUTEViewInitialized;
-
- extern Boolean gUMemoryInitialized;
-
- extern Ptr gStrippedAddress;
-
- extern TEHandle gMATextBoxTE;
-
- extern WordBreakUPP gTEDefaultWordBreak;
-
- extern VHSelect gOrthogonal[2];
-
- extern CRect gZeroRect;
-
- extern CPoint gZeroPt;
-
- extern VPoint gZeroVPt;
-
- extern VRect gZeroVRect;
-
- extern CStr255 gEmptyString;
-
- extern CRGBColor gRGBBlack;
-
- extern CRGBColor gRGBWhite;
-
- extern CRGBColor gRGBRed;
-
- extern CRGBColor gRGBGreen;
-
- extern CRGBColor gRGBBlue;
-
- //------------------------------------------------------------------------------------
- // CWhileOutlinePreferred: A simple class for setting/restoring outline preferred.
- //------------------------------------------------------------------------------------
-
- class CWhileOutlinePreferred
- {
- Boolean fPreferOutline;
- Boolean fOutlinePreferredChanged;
-
- public:
- // Constructor/destructor
- CWhileOutlinePreferred(Boolean preferOutline);
- ~CWhileOutlinePreferred();
- };
-
- //----------------------------------------------------------------------------------------
- // CStringListRsrc: A simple class for managing and accessing strings in STR# resources.
- //
- // Limitations: this class has no notion of which resource file to be used for accessing
- // the strings from the CString list resource. This could be added as an enhancement.
- //----------------------------------------------------------------------------------------
-
- class CStringListRsrc {
-
- protected:
- ResNumber fStrListID; // The ID of the STR# rsrc.
-
- CStr255 fStrListRsrcName; // The name of the STR# rsrc, this is
- // only used when adding the STR# rsrc.
-
- public:
- //----------------------------------------------------------------------------------------
- // class-scoped constants
- //----------------------------------------------------------------------------------------
- enum { kDontAddString, kAddString };
-
- //----------------------------------------------------------------------------------------
- // constructors
- //----------------------------------------------------------------------------------------
- CStringListRsrc(short strListID, const CStr255& strListRsrcName) :
- fStrListID(strListID),
- fStrListRsrcName(strListRsrcName)
- {}
- // inline constructor
-
- CStringListRsrc(short strListID) :
- fStrListID(strListID)
- { fStrListRsrcName = gEmptyString; }
- // inline constructor
-
- //----------------------------------------------------------------------------------------
- // accessors
- //----------------------------------------------------------------------------------------
- short AppendString(const CStr255& theString);
- // append theString to the STR# resource whose id is fStrListID and return its index
-
- void ClearAll();
- // clears all strings in the STR# resource
-
- short CountStrings() const;
- // returns the number of strings in the STR# resource whose id is fStrListID
-
- short FindString(const CStr255& theString, Boolean addString = kDontAddString);
- // find theString in the STR# resource whose id is fStrListID and return its index
- // if theString is not found in the STR# resource, add it if addString is kAddString
-
- void GetListName(CStr255& itsName);
- // Returns the name of the STR# list either from its field or if that is empty
- // from the actual resource
-
- void GetString(short index, CStr255& theString) const;
- // return in theString the "index" CString in the STR# resource whose id is fStrListID
-
- void RemoveAt(short index);
- // removes the CString at the specified index.
-
- void ReplaceAt(const CStr255& theString, short index);
- // replace the CString at "index" with "theString"
- };
-
-
- //----------------------------------------------------------------------------------------
- // CWMgrIterator: A simple iterator for window lists.
- //----------------------------------------------------------------------------------------
-
- class CWMgrIterator : public CIterator
- {
- private:
- WindowPtr fCurrentWindow;
-
- protected:
- Boolean fIterateForward;
-
- public:
- CWMgrIterator();
- CWMgrIterator(Boolean itsForward);
-
- virtual Boolean More(); // override
- // Returns true if there are more elements to iterate over
-
- virtual void Reset(); // override
- // Resets the iterator to begin again
-
- inline WindowPtr CurrentWMgrWindow();
- // returns the current window
-
- inline WindowPtr FirstWMgrWindow();
- // Resets the iterator to begin again and returns the first window in the window list
-
- inline WindowPtr NextWMgrWindow();
- // increments and then returns the window in the window list
-
- protected:
- virtual void Advance(); // override
- // Advances the iteration
-
- WindowPtr NextWindow(WindowPtr aWindow);
- // returns the next window in the window list, excluding gWorkPort
-
- WindowPtr PreviousWindow(WindowPtr aWindow);
- // returns the previous window in the window list, excluding gWorkPort
-
- WindowPtr FirstWindow();
- // returns the first window in the window list, excluding gWorkPort
-
- WindowPtr LastWindow();
- // returns the last window in the window list, excluding gWorkPort
-
- };
-
-
- //----------------------------------------------------------------------------------------
- // CWMgrIterator inline method definitions.
- //----------------------------------------------------------------------------------------
-
- inline WindowPtr CWMgrIterator::CurrentWMgrWindow()
- {
- return fCurrentWindow; // Always return the current window
- }
-
- inline WindowPtr CWMgrIterator::FirstWMgrWindow()
- {
- this->Reset();
- return fCurrentWindow; // Always return the first window
- }
-
- inline WindowPtr CWMgrIterator::NextWMgrWindow()
- {
- this->Advance();
- return fCurrentWindow;
- }
-
- //----------------------------------------------------------------------------------------
- // Global assembly inline function definitions.
- //----------------------------------------------------------------------------------------
-
- #if !qPowerPC
- long GetParmBlockPtr() = { 0x2008 }; // MOVE.L A0,D0
- // Return the value of register A0.
- // Useful for getting the pointer
- // to the parameter block from a
- // VBL task or a completion routine.
- #endif
-
- #if !qPowerPC
- long GetA5() = { 0x200D }; // MOVE.L A5,D0
- // Return the value of register A5.
- // Useful for getting the immediate
- // value of A5 which is not always
- // the same as CurrentA5. Generally
- // a pointer to the program's global
- // area and jump table.
-
- #if qDebug
- #ifdef __MWERKS__
- #pragma pointers_in_D0
- #endif
- Ptr GetCurStackFramePtr() = { 0x200E }; // MOVE.L A6,D0
- // Return the value of register A6.
- // Usually a pointer to the local
- // stack frame. Most often used to
- // find out the caller's name when
- // invoking a debugging routine.
-
- Ptr GetCurStackTop() = { 0x200F }; // MOVE.L A7,D0
- // Return the value of register A7.
- // Usually the top of the stack.
- // Useful for stack sniffing (not
- // a crime).
- #ifdef __MWERKS__
- #pragma pointers_in_A0
- #endif
- #endif
- #endif
-
- //----------------------------------------------------------------------------------------
- // Global function declarations that needs to always be compiled for 68000.
- //----------------------------------------------------------------------------------------
-
- void BlockSet(Ptr destPtr,
- long byteCount,
- unsigned char setVal);
-
- void CenterRectOnScreen(CRect& aRect,
- Boolean horizontally,
- Boolean vertically,
- Boolean forDialog);
-
- void ConcatNumber(const CStr255& aString,
- long aNumber,
- CStr255& theResult);
-
- TrapType GetTrapType(short theTrap);
-
- void PullApplicationToFront();
-
- void SetRGBColor(CRGBColor& RGB,
- short aRed,
- short aGreen,
- short aBlue);
-
- Boolean TrapExists(short theTrap);
-
- OSErr MAInteractWithUser(long timeOutInTicks, NMRecPtr nmReqPtr, AEIdleUPP idleProc);
- // A wrapper for AEInteractWithUser. Called before displaying a modal dialog
- // or alert. Used as our bottleneck for the Notification Manager.
-
- //----------------------------------------------------------------------------------------
- // Global function declarations
- //----------------------------------------------------------------------------------------
-
- Boolean CompareMultiByteChars(const CStr31& first,
- const CStr31& second,
- Boolean caseSens);
- // Special case single byte characters and allow case insensitive comparisons
-
- short CompareStrings(const CStr255& first,
- const CStr255& second);
-
- void CopyStr255(const CStr255& fmStr,
- Ptr toAddr);
-
- WindowPtr FindWindowBefore(WindowPtr theWindow);
-
- void DefaultSize(short& theSize);
-
- Handle DisposeIfHandle(Handle aHandle);
-
- PicHandle DisposeIfPicHandle(PicHandle aPicHandle);
-
- Ptr DisposeIfPtr(Ptr aPtr);
-
- RgnHandle DisposeIfRgnHandle(RgnHandle aRgnHandle);
-
- SectionHandle DisposeIfSectionHandle(SectionHandle aSectionHandle);
-
- UniversalProcPtr DisposeIfRoutineDescriptor(UniversalProcPtr aUniversalProcPtr);
-
- Boolean EqualBlocks(Ptr first,
- Ptr second,
- short theSize);
-
- short GetActualJustification(short justification);
-
- void GetDeskTopRegion(RgnHandle deskTopRgn);
-
- short GetFontNum(const CStr255& fontName);
-
- void GetIfColor(CRGBColor& aColor);
-
- void GetIfBkColor(CRGBColor& aColor);
-
- void GetPortTextStyle(TextStyle& theTextStyle);
-
- void MAGetTextStyle(ResNumber rsrcID, TextStyle& theTextStyle);
- // Given the rsrcID of a 'TxSt' resource, this function creates and
- // returns in theTextStyle the corresponding TextStyle record.
-
- void GetPortFontInfo(short fontNum, CStr255& fontName, short& fontSize);
-
- Boolean IsColorPort(GrafPtr port);
-
- Boolean IsAResource(Handle h);
-
- Boolean IsHandle(Handle h);
-
- Boolean IsHandleLocked(Handle h);
-
- #if qDebug
- Boolean IsHandlePurged(Handle h);
- #else
- inline Boolean IsHandlePurged(Handle h)
- {
- return (!*h);
- }
- #endif
-
- short GetWindowVariant(WindowPtr theWindow);
-
- short LengthRect(const CRect& r, VHSelect vhs);
-
- SignedByte LockHandleHigh(Handle h);
-
- VHSelect LongerSide(CRect& r);
-
- VHSelect LongerVSide(VRect& r);
-
- void LIntToHex(long decNumber, CStr31& hexNumber, short noOfDigits);
-
- short MAGetFontInfo(FontInfo& theFontInfo);
-
- short MAUseResFile(short refNum);
-
- void MATextBox(Ptr text,
- long itsLength,
- const CRect& box,
- short itsJust,
- Boolean autoWrap,
- ProcPtr wordBreak,
- Boolean eraseFirst,
- Boolean spaceForCaret,
- Boolean preferOutline = kDontPreferOutline);
-
- void MADrawString(const CStr255& s,
- const CRect& box,
- short justification,
- Boolean preferOutline = kDontPreferOutline);
-
- inline long Max(long a, long b)
- {
- return a > b ? a : b;
- }
-
- inline long Min(long a, long b)
- {
- return a < b ? a : b;
- }
-
- // Returns the bounded minimum and maximum
- long MinMax(long MinVal, long expression, long MaxVal);
-
- void NumberToHex(long theNumber,
- CStr255& hexString,
- short hexDigits);
-
- Boolean IsCommandKeyDown();
-
- Boolean IsControlKeyDown();
-
- Boolean IsOptionKeyDown();
-
- Boolean IsShiftKeyDown();
-
- long PinOnRect(const CRect& theRect, CPoint thePt);
-
- void PinOnVRect(const VRect& theRect, const VPoint& thePt, VPoint& thePin);
-
- long StripLong(void* address);
-
- void PointerToHex(long theNumber, CStr31& hexString, short hexDigits);
-
- Boolean RectsNest(const CRect& outer, const CRect& inner);
-
- Boolean VRectsNest(const VRect& outer, const VRect& inner);
-
- long RoundUp(long aNumber, short aModulus);
-
- short SetKeyScript(short newKeyScript);
-
- void SetIfColor(const CRGBColor& aColor);
-
- void SetIfBkColor(const CRGBColor& aColor);
-
- void SetPortTextStyle(const TextStyle& theTextStyle);
-
- void SetTextStyle(TextStyle& theTextStyle,
- short theFont,
- /* Style */
- short theStyle,
- short theSize,
- const CRGBColor& theColor);
-
- short UprChar(short ch);
-
- void UprStr255(CStr255& s);
-
- void UprMAName(MAName& s);
-
- short LowerChar(short ch);
-
- void LowerStr255(CStr255& s);
-
- void UseSelectionColor();
-
- void UseROMMap(Boolean resLoad);
-
- long NumBlocks(long numBytes, long blkSize);
-
- Boolean CanReadLn();
-
- Boolean CanWriteLn();
-
- Boolean VerboseIsHandle(Handle h);
-
- void WriteHandleContents(Handle theHandle);
-
- void WrLblHandleContents(const CStr255& aLabel, Handle theHandle);
-
- void WritePtr(long val);
-
- void WrLblPtr(const CStr255& aLabel, long val);
-
- void WriteBoolean(Boolean b);
-
- void WrLblBoolean(const CStr255& aLabel, Boolean b);
-
- void WriteSig(IDType theID);
-
- void WrLblSig(const CStr255& theLabel, IDType theID);
-
- void WriteHexInt(short theInt);
-
- void WrLblHexInt(const CStr255& theLabel, short theInt);
-
- void WriteHexLongint(long theLongint);
-
- void WrLblHexLongint(const CStr255& theLabel, long theLongint);
-
- void XorPat(const Pattern& patA, const Pattern& patB, Pattern& toPat);
- void CopyPat(const Pattern& pat, Pattern& toPat);
- void RotatePat(Pattern& aPattern);
- #endif
-
-
-